package com.koron.order.common.controller;

import com.github.pagehelper.PageInfo;
import com.koron.bean.base.BaseQueryBean;
import com.koron.bean.base.Response;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.order.common.bean.po.OrderAccept;
import com.koron.order.common.service.OrderAcceptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * (OrderAccept)表控制层
 *
 * @author zhouj
 * @since 2021-09-06 11:35:25
 */
@Api(tags = "工单验收")
@RestController
@RequestMapping("/orderAccept/")
public class OrderAcceptController {

    @Autowired
    private OrderAcceptService orderAcceptService;

    public String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }

    @ApiOperation(value = "保存(新增/更新) ")
    @PostMapping("saveAcceptInfo")
    public Response<Integer> saveAcceptInfo(@Validated @RequestBody OrderAccept orderAccept) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), orderAcceptService, "insertOrUpdate", Integer.class, orderAccept));
    }

    @ApiOperation(value = "新增 ")
    @PostMapping("insert")
    public Response<Integer> insert(@Validated @RequestBody OrderAccept orderAccept) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), orderAcceptService, "insert", Integer.class, orderAccept));
    }

    @ApiOperation(value = "根据id更新 ")
    @PutMapping("update")
    public Response<Integer> update(@RequestBody OrderAccept orderAccept) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), orderAcceptService, "update", Integer.class, orderAccept));
    }

    @ApiOperation(value = "根据id删除 ")
    @DeleteMapping("deleteById")
    public Response<Integer> deleteById(String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), orderAcceptService, "deleteById", Integer.class, id));
    }

    @ApiOperation(value = "根据id查询 ")
    @GetMapping("queryById")
    public Response<OrderAccept> queryById(String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), orderAcceptService, "queryById", OrderAccept.class, id));
    }

    @ApiOperation(value = "根据orderId查询 ")
    @GetMapping("queryByOrderId")
    public Response<OrderAccept> queryByOrderId(String orderId) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), orderAcceptService, "queryByOrderId", OrderAccept.class, orderId));
    }

    @ApiOperation(value = "查询列表")
    @GetMapping("queryList")
    public Response<PageInfo> queryList(OrderAccept queryBean, BaseQueryBean pageBean) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), orderAcceptService, "queryList", PageInfo.class, queryBean, pageBean));
    }

}
